let vm = new Vue({
    el: '#app',
    delimiters: ['[[', ']]'],
    data: {
        // v-model
        account: '',
        password: '',
        remembered: '',

        // v-show
        error_account: false,
        error_password: false
    },
    methods: {
        check_account(){  // 前端校验用户名
            let re = /^[a-zA-Z0-9_-]{5,20}$/;
            if (re.test(this.account)){
                //匹配成功
                this.error_account = false;
            } else {
                // 匹配失败
                this.error_account = true;
            }
        },

        check_password(){  // 前端校验密码
            let re = /^[a-zA-Z0-9_-]{8,20}$/
            if (re.test(this.password)) {
                this.error_password = false;
            } else {
                this.error_password = true;
            }
        },

        on_submit(){
            // 提交表单
            this.check_account();
            this.check_password();

            if (this.error_account == true || this.error_password == true){
                window.event.returnValue = false;
            }
        },

        // qq登录
        qq_login(){
            let next = get_query_string('next') || '/';
            let url = '/qq/login/?next=' + next;
            axios.get(url, {
                responseType: 'json'
            })
                .then(response => {
                    location.href = response.data.login_url;  // location.href的作用是从当前页面定位到response.data.login_url这个页面
                })
                .catch(error => {
                    console.log(error.response);
                })
        }

    },
})